<?php
error_reporting(0);
$mytime=array_sum(explode(' ',microtime()));
set_include_path('.' . PATH_SEPARATOR . 'library' . 
				PATH_SEPARATOR . 'models/common/' . 
				PATH_SEPARATOR . 'models/shop/' . 
				PATH_SEPARATOR . 'models/twitter/' .
				PATH_SEPARATOR . 'models/facebook/' .
				PATH_SEPARATOR . 'filter/' . 
				PATH_SEPARATOR . get_include_path());
require_once 'library/Zend/Loader.php';
Zend_Loader::registerAutoload();

// Setup controller
$controller = Zend_Controller_Front::getInstance();
$controller->setDefaultModule('shop');
$controller->setControllerDirectory(
	array(
	    'shop' => 'application/shop/controllers',
		'adminb' => 'application/adminb/controllers',
		'administrator' => 'application/administrator/controllers'
	)
);

$controller->throwExceptions(true); // should be turned on in development time 

require 'php_config/global.php';//全局配置
// bootstrap layouts

Zend_Layout::startMvc();

// load configuration
$config = new Zend_Config_Ini('php_config/config.ini','general');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);

$db=Zend_Db::factory($config->db);
$registry->set('db', $db);
Zend_Db_Table::setDefaultAdapter($db);
$db->query('SET NAMES UTF8');


//cache
Zend_Loader::loadClass('Zend_Cache');
$frontendOptions = array(
   'caching'=> true,
   'lifeTime' => 3600*24, // cache lifetime of 24 hours
   'automatic_serialization' => true,
);

$backendOptions = array(
    //'cache_dir' => MY_ROOT.'/cache/' // Directory where to put the cache files
    'compression'=>true
);

// 取得一个Zend_Cache_Core 对象

$myCache = Zend_Cache::factory('Core', 'Memcached', $frontendOptions, $backendOptions);
$registry->set('myCache', $myCache);


//ACL
$acl=new CAcl();
$registry->set('acl', $acl);

require 'php_config/common.php';//全局常量

try{
	// run!
	Zend_Session::start();
	$url = $_SERVER['REQUEST_URI'];	
	if (preg_match('/^\/category-(\d+)-(\d+)-(\d+)-(\w+)-(.+).html/', $url) ||
		preg_match('/^\/category-(\d+)-(\d+)-(\d+)-(\w+).html/', $url) ||
		preg_match('/^\/cld-(\d+)-(\w+).html/', $url) || 
		preg_match('/^\/cno-(\d+)-(\w+)\.html/', $url) || 
		preg_match('/^\/cvo-(\d+)-(\w+)\.html/', $url) || 
		preg_match('/^\/cmn-(\d+)-(\w+)\.html/', $url) || 
		preg_match('/^\/cheap-soccer-jerseys-(\d+)-(.*).html/', $url) || 
		preg_match('/^\/blog-(\d+).html/', $url) || 
		preg_match('/^\/news-(\d+)/', $url) || 
		preg_match('/^\/news/', $url) || 
		preg_match('/^\/soccer-jersey-news-(\d+)-(\w+)/', $url) || 
		preg_match('/^\/soccer_jersey_(.*).html/', $url) || 
		preg_match('/^\/promotion-merge-(.*)/', $url) || 
		preg_match('/^\/index.php\?controller=product&action=detail(.*)/', $url) ||
		preg_match('/^\/soccer\/(.*)_(\d+).html/', $url) ||
		preg_match('/^\/football_shirt_(\d+).html/', $url) ||
		preg_match('/^\/cheap-soccer-jerseys\/(.*)_(\d+).html/', $url) ||
		preg_match('/^\/player-soccer-jersey/', $url) ||
		preg_match('/^\/player-soccer-jersey\/([^_]+)_?(\d*)/', $url) ||
		preg_match('/^\/Black-Friday-Soccer-Jersey/', $url) ||
		preg_match('/^\/Christmas-Soccer-Jersey/', $url) ||
		preg_match('/^\/New-Year-2013-Soccer-Jersey/', $url) ||
		preg_match('/^\/bring-a-friend-and-earn-with-us/', $url) ||
		preg_match('/^\/?$/', $url) ||
		preg_match('/^\/soccer-jerseys\/(.*)(\/)?/', $url)) {
		$router = $controller->getRouter();
		$router->removeDefaultRoutes();
	}
	$controller->dispatch();
	//echo '<div align=center>执行时间：'.(array_sum(explode(' ', microtime()))-$mytime).' 秒</div>';
	//echo number_format(memory_get_usage());
}catch(Exception $exp){
	$contentType = 'text/html';
	header("Content-Type: $contentType; charset=utf-8");
	header("HTTP/1.1 404 Not Found");
	readfile('404.shtml');
//echo 'an unexpected error occurred.';
//echo '<h2>Unexpected Exception: ' . $exp->getMessage() . '</h2><br /><pre>';
//echo $exp->getTraceAsString();
}

/*
$result=$db->query('SELECT * FROM purple_locationfls WHERE pid=0');

$locationArray=$result->fetchAll();

$array=array();

foreach ($locationArray as $value){
	
	$array[$value['en_flname']]=$value['flid'];
	
}

$result2=$db->query('SELECT * FROM international_express');

$expressArray=$result2->fetchAll();


foreach ($expressArray as $value){
	
	$flid=$array[$value['to_station_en']];
	try{
		$db->query("UPDATE international_express SET to_station_id='$flid' WHERE expressid='".$value['expressid']."'");
	}catch(Exception $e){
		echo $value['to_station_en'];
	}
}*/